/* eslint-disable max-lines */
import DataSelect from '@/components/DataSelect';
import TauSimpleSelect from '@/components/TauSimpleSelect';
import * as BASE from '@/stores/definitions-base';
import { DatePicker2, Input, Switch, Tag } from '@alifd/next';
import { t } from '@lingui/macro';
import dayjs from 'dayjs';
import React from 'react';
import { getCities, getShifts, partners } from './api';
import { ellipsisRender } from '@/components/TauTable';
import { BusStationSelect } from '@/components/biz';

const {
  DATETIME_TEXT,
  DATE_TEXT,
  TIME_TEXT,
  EMPTY_TEXT,
  ENUMS: ENUMSBase,
  FieldsGrid: FieldGridBase,
  TitleGrid,
  column: columnBase,
  toSelectDataSource,
} = BASE;
export { DATETIME_TEXT, DATE_TEXT, EMPTY_TEXT, TIME_TEXT, TitleGrid, toSelectDataSource };

export function column(...args) {
  return columnBase(orderModel, ...args);
}

export function FieldsGrid(props) {
  return <FieldGridBase model={orderModel} {...props} />;
}

//----------------------------------------------------------------------
export const ENUMS = {
  ...ENUMSBase,
  orderType: {
    0: t`OPEN票`,
    1: t`普通票`,
    undefined: t`普通票`,
  },
  roundTripText: {
    [true]: t`往返`,
    [false]: t`单程`,
    undefined: t`单程`,
  },
  roundTrip: {
    0: t`单程`,
    1: t`往返`,
  },
  orderStatus: {
    0: t`已取消`,
    1: t`已支付`,
    2: t`已完成`,
    3: t`其他`,
    4: t`有改签`,
  },
  orderFromType: {
    0: t`微信`,
    1: t`后台`,
    2: t`H5下单`,
  },
  payType: {
    0: t`微信`,
    1: t`支付宝`,
  },
  ticketStatus: {
    0: t`已取消`,
    1: t`未乘车`,
    2: t`已乘车`,
    3: t`已完成`,
    4: t`状态未知`,
    5: t`已过期`,
    6: t`已改签`,
  },
  returnTrip: {
    0: t`去程`,
    1: t`回程`,
    undefined: t`去程`,
  },
  currency: {
    RMB: t`人民币`,
    HKD: t`港币`,
    MOP: t`澳门币`,
  },
  // <br/> - 0 已驳回<br/> - 1 申请中<br/> - 2 已提交<br/> 前端提交
  state: {
    '-1': t`已取消`,
    0: t`已驳回`,
    1: t`申请中`,
    2: t`已提交`,
  },
  // <br/> - 0 车票退款<br/> - 1 包车退款<br/> - 2 其他退款
  refundType: {
    0: t`车票退款`,
    1: t`取消订单`,
    2: t`其他退款`,
  },
  targetType: {
    COMPANY: '公司',
    PARTNER: '合伙人',
    DRIVER: '司机',
    MERCHANT: '渠道商户',
  },
  _filterChangeOrder: {
    true: t`否`,
    false: t`是`,
  },
};

export const orderModel = {
  orderNumber: {
    label: t`订单号`,
  },
  changeAssociatedOrderIds: {
    label: t`改签后/票价`,
    text: (v, r) => {
      const ticketPriceTotal = r.busOrder.orderDetails.reduce((acc, crr) => {
        const { ticketPrice } = crr;
        acc += ticketPrice;
        return acc;
      }, 0);
      return (
        <>{(v ? t`是 (${ticketPriceTotal.toFixed(2)})` : t`否`)}</>
      );
    },
  },
  subPrice: {
    label: t`订单价/实付价`,
    text: (v, r) => {
      const { originalPrice, price, changeAssociatedOrderIds } = r;
      return (
        <>{(changeAssociatedOrderIds ? t`${originalPrice.toFixed(2)} / ${price}` : t`否`)}</>
      );
    },
  },
  attribution: {
    label: t`订单归属`,
    targetId: {
      label: t`归属id`,
    },
    targetName: {
      label: t`归属名称`,
    },
    targetType: {
      label: t`归属类型`,
    },
    ui: {
      renderer: (v) => {
        const data = v || [];
        const findRes = data.filter((p) => p.targetType === 'MANAGER');
        return <>{findRes.map((p) => p.targetName).join('、')}</>;
      },
      span: 4,
    },
  },
  discountInfos: {
    label: t`优惠信息`,
    ui: {
      span: 4,
    },
  },
  discountPriceTotal: {
    label: t`优惠金额/优惠券成本`,
    ui: {
      renderer: (v, r) => {
        const { discountInfos = [] } = r || {};
        let discountAmount = 0;
        let preferentialCost = 0;
        for (const item of discountInfos) {
          const { discountPrice, cost = 0 } = item;
          discountAmount += discountPrice;
          preferentialCost += cost;
        }
        return (<span>{discountAmount?.toFixed(2)}/{preferentialCost.toFixed(2)}</span>);
      },
    },
  },
  hotel: {
    label: t`关联酒店`,
  },
  hotelPrice: {
    label: t`酒店价格`,
  },
  hotelRootPrice: {
    label: t`酒店基础价`,
  },
  taskIds: [
    {
      label: t`任务关联id`,
    },
  ],
  completionTime: {
    label: t`完成时间`,
  },
  orderChangeRemarks: {
    label: t`订单变更备注`,
  },
  username: {
    label: t`操作人账号`,
  },
  busOrder: {
    label: t`大巴订单`,
    type: {
      label: t`类型`,
      text: (v) => ENUMS.orderType[v],
    },
    orderId: {
      label: t`公司订单号`,
    },
    orderStatus: {
      label: t`状态`,
      text: (v) => ENUMS.orderStatus[v],
      ui: {},
      ui_view: {
        renderer: (v) => <Tag type="normal" className="next-tag-small" size="small" fontSize={12} color={globalThis.TAG_COLORS.warning}>{ENUMS.orderStatus[v]}</Tag>,
        // itemProps: { size: 'small' },
      },
      ui_edit: {
        renderer: (v) => <TauSimpleSelect data={toSelectDataSource(ENUMS.orderStatus)} value={v} />,
      },
      // ui: (m) => ({
      //   // renderer: m === 1 ? (v) => <TauSimpleSelect data={toSelectDataSource(ENUMS.orderStatus)} value={v} /> : undefined,
      //   renderer: (v) => <Tag type="normal" size="small" fontSize={12} color={globalThis.TAG_COLORS.warning}>{ENUMS.orderStatus[v]}</Tag>,
      //   itemProps: { size: 'small' },
      //   // renderer: m === 1 ? (v) => <TauSimpleSelect data={[...(_.transform(ENUMS.orderStatus, trans, []))]} value={v} />
      //   //   : (v) => <Tag type="normal" size="small" fontSize={12} color={globalThis.TAG_COLORS.warning}>{ENUMS.orderStatus[v]}</Tag>,
      //   // itemProps: m === 1 ? { isPreview: false } : { size: 'small' },
      // }),
    },
    consoleRemarks: {
      label: t`控制台订单备注`,
      ui: { span: 4 },
      ui_edit: {
        renderer: (v) => (<Input.TextArea value={v} />),
      },
    },
    payTime: {
      label: t`支付时间`,
      text: DATETIME_TEXT,
    },
    payType: {
      label: t`支付方式`,
      text: (v, record) => {
        const { payType } = record?.busOrder;
        return ENUMS.payType[payType];
      },
    },
    cancelOrderTime: {
      label: t`取消订单时间`,
      text: DATETIME_TEXT,
    },
    cancelRemark: {
      label: t`取消订单备注`,
    },
    refundTime: {
      label: t`退款时间`,
      text: DATETIME_TEXT,
    },
    refundPrice: {
      label: t`退款金额`,
    },
    settlementRatio: {
      label: t`退款结算比例`,
    },
    refundRemark: {
      label: t`退款备注`,
    },
    cost: {
      label: t`与公司结算价格`,
    },
    companyId: {
      label: t`公司id`,
    },
    directionalCompany: {
      label: t`定向公司id`,
    },
    companyName: {
      label: t`公司`,
    },
    agent: {
      label: t`代理商`,
    },
    effTime: {
      label: t`有效时间`,
      text: DATETIME_TEXT,
    },
    from: {
      label: t`去程开始信息`,
      city: {
        label: t`出发城市`,
        ui: {
          renderer: (v) => <DataSelect onFetch={() => getCities({ type: '0' })} value={v} labelField="cityText" valueField="city" />,
          itemProps: { required: true },
        },
      },

      station: {
        label: t`出发站点`,
        ui: {
          renderer: (v, order) => <BusStationSelect forRoute fromCity={order?.busOrder?.from?.city} toCity={order?.busOrder?.to?.city} isOffStation={false} value={v} />,
          itemProps: { required: true },
        },
      },
      stationName: {
        label: t`去程上车站点`,
      },
      onAddress: {
        label: t`站点详细地址`,
        ui: { span: 2 },
      },
    },
    returnFrom: {
      label: t`回程开始信息`,
      city: {
        label: t`出发城市`,
        renderer: (v) => <DataSelect onFetch={() => getCities({ type: '0' })} value={v} labelField="cityText" valueField="city" />,
        itemProps: { required: true },
      },
      station: {
        label: t`出发站点`,
        ui: {
          renderer: (v, order) => <BusStationSelect forRoute fromCity={order?.busOrder?.returnFrom?.city} toCity={order?.busOrder?.returnTo?.city} isOffStation={false} value={v} />,
          itemProps: { required: true },
        },
      },
      stationName: {
        label: t`回程上车站点`,
      },
      onAddress: {
        label: t`站点详细地址`,
        ui: { span: 2 },
      },
    },
    to: {
      label: t`去程结束信息`,
      city: {
        label: t`到达城市`,
        ui: {
          renderer: (v, formData) => <DataSelect onFetch={(n, args) => getCities(args)} args={{ type: '1', city: formData.busOrder.from?.city }} value={v} labelField="cityText" valueField="city" />,
          itemProps: { required: true },
        },
      },
      station: {
        label: t`到达站点`,
        ui: {
          renderer: (v, order) => <BusStationSelect forRoute fromCity={order?.busOrder?.from?.city} toCity={order?.busOrder?.to?.city} isOffStation value={v} />,
          itemProps: { required: true },
        },
      },
      stationName: {
        label: t`去程下车站点`,
      },
      offAddress: {
        label: t`站点详细地址`,
        ui: { span: 2 },
      },
    },
    returnTo: {
      label: t`回程结束信息`,
      city: {
        label: t`到达城市`,
        ui: {
          renderer: (v, formData) => <DataSelect onFetch={(n, args) => getCities(args)} args={{ type: '1', city: formData.busOrder.from?.city }} value={v} labelField="cityText" valueField="city" />,
          itemProps: { required: true },
        },
      },
      station: {
        label: t`到达站点`,
        ui: {
          renderer: (v, order) => <BusStationSelect forRoute fromCity={order?.busOrder?.returnFrom?.city} toCity={order?.busOrder?.returnTo?.city} isOffStation value={v} />,
          itemProps: { required: true },
        },
      },
      stationName: {
        label: t`回程下车站点`,
      },
      offAddress: {
        label: t`站点详细地址`,
        ui: { span: 2 },
      },
    },
    isOpen: {
      label: t`去程是否open票`,
    },
    returnIsOpen: {
      label: t`回程是否open票`,
    },
    isRoundTrip: {
      label: t`单双程`,
      text: (v) => ENUMS.roundTripText[v],
      ui: {
        renderer: (v) => <Switch checked={v} autoWidth checkedChildren={t`往返`} unCheckedChildren={t`单程`} />,
      },
    },
    collectorName: {
      label: t`取票人`,
      text: EMPTY_TEXT,
    },
    collectorPhone: {
      label: t`取票人电话`,
      text: EMPTY_TEXT,
    },
    partnerId: {
      label: t`合伙人`,
      ui: {
        renderer: (v) => <DataSelect hasClear onFetch={(page) => partners({ page })} value={EMPTY_TEXT(v)} labelField="fullname" valueField="username" />,
      },
    },
    fullname: {
      label: t`下单人姓名`,
      ui: {
        itemProps: {
          required: true,
        },
      },
    },
    username: {
      label: t`下单人`,
    },
    phone: {
      label: t`下单人电话`,
      text: EMPTY_TEXT,
      ui: {
        // renderer: m === 1 && (() => <InputSelect onFetch={usersForMobile} labelField="fullname" valueField="mobile" />),
        itemProps: {
          required: true,
          format: 'tel',
        },
      },
    },
    currencyId: {
      label: t`币种`,
      ui: {
        renderer: (v) => <TauSimpleSelect data={toSelectDataSource(ENUMS.currency)} value={v} />,
        itemProps: {
          required: true,
        },
      },
    },
    shift: {
      label: t`去程班次信息`,
      date: {
        label: t`实际上车时间`,
        text: DATETIME_TEXT,
        ui: {
          renderer: (v) => <DatePicker2 value={v} preset={{ [t`今日`]: () => dayjs() }} renderPreview={DATETIME_TEXT} />,
          itemProps: { required: true },
        },
      },
      companyName: {
        label: t`公司名称`,
      },
      scheduledShiftTime: {
        label: t`预计上车时间`,
        text: DATETIME_TEXT,
      },
      scheduleId: {
        label: t`班次`,
        ui: {
          itemProps: { required: true },
          renderer: (v, order) => (<DataSelect
            onFetch={(n, args) => getShifts(args)}
            args={{
              currencyId: order.busOrder?.currencyId,
              departureDate: order.busOrder?.shift?.date?.toJSON(),
              originId: order.busOrder?.from?.station,
              destinationId: order.busOrder?.to?.station,
              isReturn: order.busOrder?.isRoundTrip ? 1 : 0,
              priceType: '',
            }}
            value={v}
            mapper={(item) => ({
              label: `${item.runStartTime} ${item.startStationName}-${item.endStationName}`,
              value: item.id,
              ...item,
            })}
          />),
        },
      },
    },
    returnShift: {
      label: t`回程班次信息`,
      date: {
        label: t`实际上车时间`,
        text: DATETIME_TEXT,
        ui: {
          renderer: (v) => <DatePicker2 value={v} preset={{ [t`今日`]: () => dayjs() }} renderPreview={DATETIME_TEXT} />,
          itemProps: { required: true },
        },
      },
      companyName: {
        label: t`公司名称`,
      },
      scheduledShiftTime: {
        label: t`预计上车时间`,
        text: DATETIME_TEXT,
      },
      scheduleId: {
        label: t`班次`,
        ui: {
          itemProps: { required: true },
          renderer: (v, order) => (<DataSelect
            onFetch={(n, args) => getShifts(args)}
            args={{
              currencyId: order.busOrder?.currencyId,
              departureDate: order.busOrder?.returnShift?.date?.toJSON(),
              originId: order.busOrder?.returnFrom?.station,
              destinationId: order.busOrder?.returnTo?.station,
              isReturn: order.busOrder?.isRoundTrip ? 1 : 0,
              priceType: '',
            }}
            value={v}
            mapper={(item) => ({
              label: `${item.runStartTime} ${item.startStationName}-${item.endStationName}`,
              value: item.id,
              ...item,
            })}
          />),
        },
      },
    },
    priceType: {
      label: t`价格应用界面`,
    },
    prices: [
      {
        label: t`班次下票种价格枚举`,
        fee: {
          label: t`价格`,
        },
        isReturn: {
          label: t`单双程`,
        },
        lawTicketType: {
          label: t`价格级别`,
        },
        priceId: {
          label: t`票价id`,
        },
        stdPrivFlg: {
          label: t`票价类型`,
        },
        ticketCategoryId: {
          label: t`路线票种`,
        },
        ticketCategoryName: {
          label: t`票种名称`,
        },
        ticketType: {
          label: t`票价类型名称`,
        },
        ticketTypeId: {
          label: t`票种类型id`,
        },
        ticketCategoryLineId: {
          label: t`路线票种id`,
        },
      },
    ],
    orderDetails: [
      {
        label: t`订单车票每程详情列表`,
        ticketTime: { // 前端新增
          label: t`上车时间`,
          text: DATETIME_TEXT,
        },
        passenger: {
          label: t`乘客`,
        },
        passengerTel: {
          label: t`乘客电话`,
        },
        busTicketType: {
          label: t`票种类型`,
        },
        ticketCategoryLineId: {
          label: t`线路票种价格`,
        },
        passengerEmail: {
          label: t`电子邮箱`,
        },
        passengerFlightNo: {
          label: t`航班号码`,
        },
        idCard: {
          label: t`身份证号`,
        },
        directorIdType: {
          label: t`身份证类型`,
        },
        isReturn: {
          label: t`行程`,
          text: (v) => ENUMS.returnTrip[v],
        },
        price: {
          label: t`票价`,
        },
        priceId: {
          label: t`关联价格定义中的标识`,
        },
        relatedTicket: {
          label: t`关联回程票号与回程`,
        },
        busScheduleId: {
          label: t`预定班次编号`,
        },
        shiftTime: {
          label: t`预定班次时间`,
          text: (v, r) => {
            return <>{v ? DATETIME_TEXT(v) : DATETIME_TEXT(r.ticketTime)}</>;
          },
        },
        runDate: {
          label: t`行程日期`,
          text: DATE_TEXT,
        },
        runTime: {
          label: t`行程时间`,
          text: TIME_TEXT,
        },
        checkIn: {
          label: t`上车班次信息`,
          busScheduleId: {
            label: t`实际班次编号`,
          },
          checkInTime: {
            label: t`上车时间`,
          },
          ticketChecker: {
            label: t`验票员`,
          },
        },
        operatingState: {
          label: t`第三方车票状态`, // TIME_TEXT
        },
        state: {
          label: t`状态`,
          text: (v, r) => {
            const text = ENUMS.ticketStatus[v];
            const isChange = r?.originalTicketCode;
            return <>{`${text} ${isChange ? '(有改签)' : ''}`}</>;
          },
        },
        stateName: {
          label: t`车票状态`,
        },
        ticketCode: {
          label: t`车票号`,
        },
        takeTicketCode: {
          label: t`取票码`,
          text: (v) => v || t`无`,
        },
        qrCodeInfo: {
          label: t`取票码`,
          text: (v) => v || t`无`,
        },
        seats: {
          label: t`座位号`,
        },
        cancelTime: {
          label: t`客户申请取消时间`,
          text: DATETIME_TEXT,
        },
        ticketPrice: {
          label: t`票价`,
          text: (v) => <>{v && v.toFixed(2)}</>,
        },
        fee: { // 前端新增字段
          label: t`票价`,
          text: (v, record) => {
            const { isReturn } = record;
            return isReturn === '0' ? v : '';
          },
        },
      },
    ],
    remarks: {
      label: t`客户订单备注`,
      ui_view: {
        renderer: (v) => <Input.TextArea value={v} />,
        span: 4,
      },
      ui_edit: {
        renderer: (v) => {
          return (
            <Input.TextArea value={v} />
          );
        },
        span: 4,
      },
    },
    routeText: { // 前端新增字段
      label: t`线路`,
      text: (v, { busOrder }) => `${busOrder?.from?.stationName}-${busOrder?.to?.stationName}`,
      ui_table: {
        renderer: ellipsisRender,
      },
    },
  },
  transactionId: {
    label: t`微信支付订单号`,
  },
  prepayId: {
  },
  price: {
    label: t`价格/实付`,
    text: (v, r) => {
      const { originalPrice } = r;
      return <span>{t`${originalPrice?.toFixed(2) || (v || 0).toFixed(2)} / ${(v || 0).toFixed(2)}`}</span>;
    },
  },
  oldChangePrice: {
    label: t`原价/实付`,
    text: (v, r) => {
      const { originalPrice } = r;
      return <span>{t`${originalPrice?.toFixed(2) || (v || 0).toFixed(2)} / ${(v || 0).toFixed(2)}`}</span>;
    },
  },
  currency: {
    label: t`币种`,
  },
  refundAmount: {
    label: t`退款金额`,
  },
  orderType: {
    label: t`订单类型`, // ：1-包车订单 2-班车订单 3-巴士订单
  },
  relation: {
    label: t`关联订单`, // 订单增加字段：关联订单，记录发起返空线路的原订单。不为空则表示为特惠订单。
  },
  settlementId: {
    label: t`结算id`,
  },
  unfrozenFunds: {
    label: t`是否解冻资金`,
  },
  closingOfDistribution: {
    label: t`是否分账结束`,
  },
  refundInfos: [
    {
      label: t`退款信息集合`,
      id: {
        label: t`标识`,
      },
      user: {
        label: t`退款方`,
      },
      ticketCode: {
        label: t`车票号`,
      },
      distanceTime: {
        label: t`距离时间`,
      },
      refund: {
        label: t`是否退款`,
      },
      recommendedPrice: {
        label: t`建议退款金额`,
      },
      refundPrice: {
        label: t`退款金额`,
      },
      originalPrice: {
        label: t`原价`,
      },
      cancelTime: {
        label: t`申请退款时间`,
      },
      cancelRemark: {
        label: t`申请退款原因`,
      },
      refundTime: {
        label: t`退款时间`,
      },
      operatorRefundTime: {
        label: t`第三方退款时间`,
        text: (v, record) => {
          const { operatorRefundTime } = record;
          return DATETIME_TEXT(operatorRefundTime);
        },
      },
      refundRemark: {
        label: t`退款说明`,
      },
      taskId: {
        label: t`关联任务id`,
      },
      taskState: {
        label: t`任务状态`,
      },
      workOrderState: {
        label: t`工单状态`,
      },
    },
  ],
  crBy: {
    label: t`创建者`,
  },
  upBy: {
    label: t`最后修改者`,
  },
  crDate: {
    label: t`下单时间`,
    text: DATETIME_TEXT,
  },
  upDate: {
    label: t`最后修收时间`,
  },
  tenantId: {
    label: t`租户ID`,
  },
  id: {
    label: t`订单号`,
  },
  partnerName: { // 前端新增字段
    label: t`合伙人`,
    text: (v) => v || t`无`,
  },

  // 退款记录
  applicationId: {
    label: t`申请编号`,
  },
  state: {
    label: t`退款申请状态`,
    text: (v) => ENUMS.state[v],
  },
  refundId: {
    label: t`退款流水号`,
  },
  serviceCharge: {
    label: t`手续费`,
  },
  type: {
    label: t`退款类型`,
    text: (v) => ENUMS.refundType[v],
  },
  refunded: {
    label: t`财务是否退款<br/> - false 未退款<br/> - true 已退款`,
  },
  refundTime: {
    label: t`实际退款时间`,
    text: DATETIME_TEXT,
  },
  distanceTime: {
    label: t`距离时间`,
  },
  cancelTime: {
    label: t`退款申请时间`,
    text: DATETIME_TEXT,
  },
  refundPrice: {
    label: t`申请退款金额`,
    text: (v) => <span>{v?.toFixed(2)}</span>,
  },
  cancelRemark: {
    label: t`申请说明`,
  },
  rejectRemark: {
    label: t`驳回说明`,
  },
  rejectTime: {
    label: t`驳回时间`,
  },
  attachments: [{
    label: t`附件`,
    title: {
      label: t`附件标题`,
    },
    description: {
      label: t`附件说明`,
    },
    binaryId: [{
      label: t`附件id`,
    }],
  }],
  orderInfo: {
    label: t`关联订单信息`,
    directRoute: {
      label: t`包车订单必须字段，本次退款是针对哪个任务<br/> false-A段/直达<br/> true-B段`,
    },
    orderId: {
      label: t`订单id`,
    },
    suborderId: {
      label: t`子订单号`,
    },
    orderType: {
      label: t`订单类型：1-包车订单 2-班车订单 3-巴士订单`,
    },
    orderPrice: {
      label: t`订单价格`,
    },
    orderState: {
      label: t`订单状态`,
    },
    orderTime: {
      label: t`出行时间`,
    },
    name: {
      label: t`申请人`,
    },
  },
  refundPayers: [{
    label: t`退款出资方，如果没有调整分账方数据则不需要上传`,
    pendingSettlementAmount: {
      label: t`待分账金额（单位：分）`,
    },
    settled: {
      label: t`是否分账<br/> false - 未分账（还可调整分账方和退款）<br/> true - 已分账（不可调整分账方，如果去退款需要提示已分账是否还进行退款）`,
    },
    refundedAmount: {
      label: t`已退款金额（单位：分）`,
    },
    contributionAmount: {
      label: t`本次退款出资金额（单位：分）`,
    },
    targetType: {
      label: t`帐户类型<br/> 由调用方根据分账方身份类型定义，例如：COMPANY,PARTNER,CHANNEL等`,
    },
    targetId: {
      label: t`targetType下的帐户标识`,
    },
    targetName: {
      label: t`帐户名`,
    },
  }],
  ticketRefundInfos: [{
    label: t`车票退款信息<br/> 注：如果只是忽略车票则只需要把忽略的车票传递上来`,
    ticketCode: {
      label: t`车票号`,
    },
    isReturn: {
      label: t`是否回程 0：去程，1：回程`,
    },
    passengerName: {
      label: t`乘客名`,
    },
    originalPrice: {
      label: t`原票价`,
    },
    serviceCharge: {
      label: t`手续费`,
    },
    operatingState: {
      label: t`第三方状态`,
    },
    state: {
      label: t`车票状态`,
    },
    refundPrice: {
      label: t`退款金额`,
    },
    operatorRefundPrice: {
      label: t`第三方退款金额`,
    },
    operatorRefundTime: {
      label: t`运营商退款时间`,
    },
  }],
  source: {
    label: t`订单来源`,
    text: (v, record) => {
      const { targetType, targetName } = record?.source || {};
      if (targetType) {
        return ellipsisRender(`${ENUMS.targetType[targetType]} / ${targetName}`);
      } else {
        return t`无`;
      }
    },
  },
  // 前端新增
  receiveName: {
    label: t`客户经理`,
    text: (v, r) => {
      const data = r?.attribution || [];
      const findRes = data.filter((p) => p.targetType === 'MANAGER');
      return <>{findRes.map((p) => p.targetName).join('、')}</>;
    },
    ui: {
      renderer: (v, r) => {
        const data = r?.attribution || [];
        const findRes = data.filter((p) => p.targetType === 'MANAGER');
        return <>{findRes.map((p) => p.targetName).join('、')}</>;
      },
    },
  },
  attributionName: {
    label: t`归属名称`,
    text: (v, r) => {
      const data = r?.attribution || [];
      const findRes = data.filter((p) => p.targetType !== 'MANAGER');
      return <>{findRes.map((p) => p.targetName).join('、')}</>;
    },
    ui: {
      renderer: (v, r) => {
        const data = r?.attribution || [];
        const findRes = data.filter((p) => p.targetType !== 'MANAGER');
        return <>{findRes.map((p) => p.targetName).join('、')}</>;
      },
    },
  },
  sourceGroup: {
    label: t`来源/归属/经理`,
    text: (v, r) => {
      const { targetType, targetName } = r?.source || {};
      const data = r?.attribution || [];
      const findRes = data.filter((p) => p.targetType !== 'MANAGER');

      const manager = r?.attribution || [];
      const findManager = manager.filter((p) => p.targetType === 'MANAGER');

      const source = targetType ? `${ENUMS.targetType[targetType]}·${targetName}` : '无';
      const belongTo = `${findRes.map((p) => p.targetName).join('、') || '无'}`;
      const managerInfo = `${findManager.map((p) => p.targetName).join('、') || '无'}`;
      return ellipsisRender(`${source}/${belongTo}/${managerInfo}`);
    },
  },
  // difference: {
  //   label: t`差价`,
  //   text: (v, r) => {
  //     const { price } = r;
  //     return <>{(price - v).toFixed(2)}</>;
  //   },
  // },
};

